# 99 案例

# 100 Json的数据格式转换
# import json
#
# # 准备列表，列表内每一个元素都是字典，将其转换为JSON
# data = [{"name": "张大山", "age": 11}, {"name": "王大锤", "age": 13}, {"name": "赵小虎", "age": 16}]
# json_str = json.dumps(data, ensure_ascii=False)
# print(type(json_str))
# print(json_str)
#
# # 准备字典，将其转换为JSON
# d = {"name": "周杰轮", "addr": "台北"}
# json_str = json.dumps(d, ensure_ascii=False)
# print(type(d))
# print(type(json_str))
# print(json_str)
#
# # 将JSON字符串转换为Python的数据类型
# s = '[{"name": "张大山", "age": 11}, {"name": "王大锤", "age": 13}, {"name": "赵小虎", "age": 16}]'
# l = json.loads(s)
# print(type(l))
# print(l)
#
# # 将JSON的字符串转换为Python的类型
# s = '{"name": "周杰轮", "addr": "台北"}'
# d = json.loads(s)
# print(type(d))
# print(d)

# 101 pyecharts模块简介
# import pyecharts 的介绍和安装

# 102 pyechart的入门介绍
# 导包
# from pyecharts.charts import Line
# from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
#
# # 创建一个折线对象
# line = Line()
#
# # 添加x轴数据
# line.add_xaxis(['China', 'America', 'England'])
#
# # 添加y轴数据
# line.add_yaxis('GDP', [30, 20, 10])
#
# # 设置全局配置项
# line.set_global_opts(
#     title_opts=TitleOpts(title='GDP展示', pos_left='center', pos_bottom="1%"),
#     legend_opts=LegendOpts(is_show=True),
#     toolbox_opts=ToolboxOpts(is_show=True),
#     visualmap_opts=VisualMapOpts(is_show=True)
# )
#
# # 渲染数据
# line.render()

# 104 生成折线图
# import json
# from pyecharts.charts import Line
# from pyecharts.options import LabelOpts, TitleOpts
#
# # 处理数据
# f_us = open('E:/Desktop/美国.txt', 'r', encoding='UTF-8')
# us_data = f_us.read()
#
# f_jp = open('E:/Desktop/日本.txt', 'r', encoding='UTF-8')
# jp_data = f_jp.read()
#
# f_in = open('E:/Desktop/印度.txt', 'r', encoding='UTF-8')
# in_data = f_in.read()
#
# # 去掉不合理的开头
# us_data = us_data.replace('jsonp_1629344292311_69436(', '')
# jp_data = jp_data.replace('jsonp_1629350871167_29498(', '')
# in_data = in_data.replace('jsonp_1629350745930_63180(', '')
#
# # 去掉不合理的结尾
# us_data = us_data[:-2]
# in_data = in_data[:-2]
# jp_data = jp_data[:-2]
#
# # JSON转Python字典
# us_dict = json.loads(us_data)
# in_dict = json.loads(in_data)
# jp_dict = json.loads(jp_data)
#
# # 获取trend key
# us_trend_data = us_dict['data'][0]['trend']
# jp_trend_data = jp_dict['data'][0]['trend']
# in_trend_data = in_dict['data'][0]['trend']
#
# # 获取日期数据，用于x轴，取2020年（到下标314结束）
# us_x_data = us_trend_data['updateDate'][:314]
# jp_x_data = jp_trend_data['updateDate'][:314]
# in_x_data = in_trend_data['updateDate'][:314]
#
# # 获取确认数据，用于Y轴，取2020年（到下标314结束）
# us_y_data = us_trend_data['list'][0]['data'][:314]
# jp_y_data = jp_trend_data['list'][0]['data'][:314]
# in_y_data = in_trend_data['list'][0]['data'][:314]
#
# # 生成图表
# line = Line()
#
# # 添加x轴数据
# line.add_xaxis(us_x_data)
#
# # 添加y轴数据
# line.add_yaxis("美国确诊人数", us_y_data, label_opts=LabelOpts(is_show=False))  # 添加美国的y轴数据
# line.add_yaxis("日本确诊人数", jp_y_data, label_opts=LabelOpts(is_show=False))  # 添加日本的y轴数据
# line.add_yaxis("印度确诊人数", in_y_data, label_opts=LabelOpts(is_show=False))  # 添加印度的y轴数据
#
# # 设置全局选项
# line.set_global_opts(
#     title_opts=TitleOpts(title="2020年美日印三国确诊人数对比折线图", pos_left="center", pos_bottom="1%")
# )
#
# line.render()
#
# f_us.close()
# f_jp.close()
# f_in.close()

# 105 数据可视化案例--地图
